from flask_sqlalchemy import SQLAlchemy
from flask import Flask

# import pymysql

app = Flask(__name__)
# 连接Mysql数据库
# app.config|["SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://root:123456@127.0.0.1:3306/test'
#
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///' + 'D:/sql/test/first.db'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = "asphodel"

db = SQLAlchemy(app)


# 主演表
class LeadingActor(db.Model):
    __tablename__ = "leading_actor"
    # id
    id = db.Column(db.Integer, primary_key=True)
    # 名字
    name = db.Column(db.String(32), nullable=False)
    # 角色
    adorn = db.Column(db.String(42), nullable=True)
    # 所属视频
    video_id = db.Column(db.Integer, db.ForeignKey("video.id"))


# 视频表
class Video(db.Model):
    __tablename__ = "video"
    # 主键
    id = db.Column(db.Integer, primary_key=True)
    # 视频名字
    name = db.Column(db.String(64), nullable=False)
    # 上映时间
    time = db.Column(db.Integer, nullable=False)
    # 导演
    director = db.Column(db.String(32), nullable=False)
    # 简介·
    content = db.Column(db.String, nullable=False)
    # 视频链接
    url = db.Column(db.String, nullable=False)
    # 图片链接
    img_url = db.Column(db.String, nullable=False)
    # 主演
    leading_actor = db.relationship("LeadingActor", backref="video")


if __name__ == '__main__':
    db.create_all()
    # db.drop_all()
